﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using Function;
using System.Data;

namespace UI.Module.Coin
{
    public partial class CoinManage : System.Web.UI.Page
    {
        protected ST_InvestorMore model = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            model = new ST_InvestorMoreBLL().GetModel(Method.CurrentUserID);
            if (model == null)
            {
                MessageBox_Page McBx = new MessageBox_Page();//实例化对话框
                string RemarkString;
                RemarkString = "未找到对象";

                McBx.Title = "系统提示";
                McBx.AddContent(RemarkString);
                McBx.Type = MsgType.Error;
                McBx.AddUrl("返回", "../../Module/User/UserMsge.aspx", UrlType.Href);
                MessageEvent.MessageBox(McBx, "../../ErrorPage/ShowMsg.aspx");
            }
            if (model.GetCoinPwChanged==1)
            {
                div_getCoinPwd.Attributes.CssStyle.Add("display","block");
            }
            //账户余额
            lblCoin_GetedCoin.Text = (model.Coin + model.GetedCoin).ToString();
            lblcoin1.Text = model.Coin.ToString();
            lblgetedcoin1.Text = model.GetedCoin.ToString();
            //总收益
            lblALLCoin.Text = model.AllCoin.ToString();
            //可提现
            lblCoin.Text = model.Coin.ToString();
            //正在提现
            lblGetedCoin.Text = model.GetedCoin.ToString();
            //已提现
            lblAllCutCoin.Text = model.AllCutCoin.ToString();

        }

        string Message = "";
        private void Bind(string Where_String = "")
        {
            int RecordCount = 0;
            DataTable Page_Dt = new DataTable();
            Page_Dt = BLL.PageQuery2005_BLL.SelectPage(out RecordCount, "[id],[Code],[InvestorID],(select note from DY_BankInfo where code= [BankID]) as BankName,[BankCode],[Owner],[Coin],[ApplyCoin],[ApplyTime],[AuditTime],[PayTime],[State],(select Note from DY_GetCoinState where code=[State]) as StateName", "[ST_GetCoinApply]", " [InvestorID]=" + Method.CurrentUserID, "[ID] desc", Pager.CurrentPageIndex,
            Pager.PageSize, PubConstant.DataBaseTarget.JHShop, out Message);

            if (!string.IsNullOrEmpty(Message))
            {
                MessageBox_Page McBx = new MessageBox_Page();//实例化对话框
                string RemarkString;
                RemarkString = "数据查询失败";

                McBx.Title = "系统提示";
                McBx.AddContent(RemarkString);
                McBx.Type = MsgType.Error;
                McBx.AddUrl("返回", "../../Module/User/UserMsge.aspx", UrlType.Href);
                MessageEvent.MessageBox(McBx, "../../ErrorPage/ShowMsg.aspx");
                return;
            }
            grdlist.DataSource = Page_Dt;
            grdlist.DataBind();
            this.Pager.RecordCount = RecordCount;
        }

        protected void grdlist_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                int indexID = (this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize + e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = indexID.ToString();
            }
        }

        protected void Pager_BindData(object sender, EventArgs e)
        {
            Bind((hidWhere.Value ?? "").ToString());
        }
    }
}